module.exports = `

  enum DocType {
    question
    page
    folder
  }

  input DocumentPayload {
    id: Int
    name: String!
    type: DocType!
    data: JSON
    layout: JSON
    meta: JSON
    endAt: String
  }

  type Document {
    id: ID!
    isPublished: Int
    name: String!
    type: DocType!
    data: JSON
    layout: JSON
    meta: JSON
    createdAt: String
    updatedAt: String
    user: User
    unreadCount: Int
    endAt: Date
    isExpired: Boolean
    answerers: [User]
    tasks: [Task]
  }

  type PageModalDocument implements Page{
    totalCount: Int
    hasMore: Boolean
    totalPages: Int
    pageIndex: Int
    pageSize: Int
    rows: [Document]
  }

  type DocumentCursorPage {
    results: [Document]
    cursors: Cursor
  }

  extend type Query {
    # 获取当前用户所有的文档/作业列表
    documents(pageIndex: Int = 0, pageSize: Int = 20): PageModalDocument
    # 通过 ID 获取文档/作业
    getDocumentById(id: ID): Document
    # 根据Tag获取文档列表
    findDocumentsByTagId(tagId: Int, cursor: CursorInput): DocumentCursorPage

    # 根据Tag获取文档列表
    documentUnpublishes: [Document!]
  }

  extend type Mutation {
    # 创建文档/作业
    createDocument(input: DocumentPayload!): Document
    # 创建文档/作业
    documentPublish(documentId: Int!, groupIds: [Int!]!, endAt: String, prePublishAt: String): [Task]

    # 布置作业
    documentArrange(
      name: String!,
      blocks: JSON,
      groupIds: [Int!]!,
      endAt: String,
      prePublishAt: String
    ): [Task]

    # 创建文档/作业
    homeworkPublish(
      title: String,
      groupIds: [Int],
      prePublishAt: String,
      endAt: String,
      textbookId: Int,
      courseId: Int,
      exercises: [JSON],
      descriptionBlocks: [JSON]
    ): [Task]

    # 更新文档/作业
    updateDocument(docId: ID!, input: DocumentPayload!): Document

    # 删除文档/作业
    #removeDocument(docId: ID!): Document
  }

`
